<?php
declare (strict_types = 1);

namespace app\common\model;

use think\Model;
use think\model\concern\SoftDelete;
class AdminDlrecord extends Model
{
    use SoftDelete;
     protected $deleteTime = "delete_time";
     public function adminuser()
     {
         return $this->belongsTo(AdminUser::class, 'openid','openid')->visible(['nickname','headimgurl']);;
     }
     public function dianliang()
     {
         return $this->belongsTo(AdminDianliang::class, 'qxid','id')->visible(['qxname']);;
     }
     
    // 获取列表
    public static function getList()
    {
        $where = [];
        $limit = input('get.limit');
        
               //按Openid查找
               if ($openid = input("openid")) {
                   $where[] = ["openid", "like", "%" . $openid . "%"];
               }
               //按区县查找
               if ($qxid = input("qxid")) {
                   $where[] = ["qxid", "like", "%" . $qxid . "%"];
               }
        $list = self::with(['adminuser','dianliang'])->order('id','desc')->where($where)->paginate($limit);
        return ['code'=>0,'data'=>$list->items(),'extend'=>['count' => $list->total(), 'limit' => $limit]];
    }
    
    public static function getmodelbyopenid($openid)
    {
        return self::where('openid',$openid)->find();
    }
}
